package acm.蓝桥1;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
 * https://www.dotcpp.com/oj/problem1439.html
 */
public class 冒泡排序 {
//    static Map<Integer,Integer> map=new HashMap<>();
    static int[][] arr;
    static int n;

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            arr[i][0] =sc.nextInt();
        }
        long res = bubble();
        System.out.println(res);
    }
    public static long bubble(){
        for (int i = 0; i < arr.length; i++) {
            boolean flag=false;
            for (int j =0; j < arr.length - i - 1; j++) {
                if (arr[j][0]>arr[j + 1][0]) {
                    arr[j][1]++;
                    arr[j+1][1]++;
                    int[] temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    flag=true;
                }
            }
            if (!flag){
                break;
            }
        }
        long res=0;
        for (int i = 0; i < arr.length; i++) {
            res+=(arr[i][1]+1)*arr[i][1]/2;
        }
        return res;
    }
    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
